package com.hsteach.web.controller.calendar;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.domain.model.AuthInfo;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.common.utils.SecurityUtils;
import com.hsteach.common.utils.poi.ExcelUtil;
import com.hsteach.enums.BooleanEnum;
import com.hsteach.service.calendar.CalendarPlanService;
import com.hsteach.web.controller.calendar.dto.AddCalendarPlanDto;
import com.hsteach.web.controller.calendar.dto.UpdateCalendarPlanDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hsteach.dao.domain.calendar.CalendarPlan;

/**
 * 周行事历工作计划Controller
 * 
 * @author fanxquer
 * @date 2023-12-02
 */
@Api(value = "周行事历计划管理", tags = "周行事历计划管理")
@RestController
@RequestMapping("/web/calendar/plan")
public class CalendarPlanController extends BaseController
{
    @Autowired
    private CalendarPlanService calendarPlanService;

    /**
     * 查询周行事历周工作计划列表
     */
    @ApiOperation("查询周工作计划列表")
    @GetMapping("/week/{calendarId}")
    public TableDataInfo listAllWeek(@PathVariable("calendarId") Long calendarId)
    {
        CalendarPlan query = new CalendarPlan();
        query.setCalendarId(calendarId);
        query.setPlanType(1);
        query.setDelStatus(BooleanEnum.TRUE.getCode());
        query.setOrgCode(SecurityUtils.getAuthInfo().getOrgCode());
        List<CalendarPlan> list = calendarPlanService.selectCalendarPlanList(query);
        return getDataTable(list);
    }

    /**
     * 查询周行事历月工作计划列表
     */
    @ApiOperation("查询月工作计划列表")
    @GetMapping("/month/{calendarId}")
    public TableDataInfo listAllMonth(@PathVariable("calendarId") Long calendarId)
    {
        CalendarPlan query = new CalendarPlan();
        query.setCalendarId(calendarId);
        query.setPlanType(2);
        query.setDelStatus(BooleanEnum.TRUE.getCode());
        query.setOrgCode(SecurityUtils.getAuthInfo().getOrgCode());
        List<CalendarPlan> list = calendarPlanService.selectCalendarPlanList(query);
        return getDataTable(list);
    }

    /**
     * 新增周行事历工作计划
     */
    @ApiOperation("新增周工作计划")
    @PostMapping("/week")
    public AjaxResult addWeekPlan(@RequestBody AddCalendarPlanDto dto)
    {
        AuthInfo authInfo = SecurityUtils.getAuthInfo();
        CalendarPlan insert = new CalendarPlan();
        BeanUtils.copyProperties(dto, insert);
        insert.setDelStatus(BooleanEnum.TRUE.getCode());
        insert.setPlanType(1);
        insert.setCreateBy(authInfo.getPersonId());
        insert.setOrgCode(authInfo.getOrgCode());
        return toAjax(calendarPlanService.insertCalendarPlan(insert));
    }

    /**
     * 新增周行事历工作计划
     */
    @ApiOperation("新增月工作计划")
    @PostMapping("/month")
    public AjaxResult addMonthPlan(@RequestBody AddCalendarPlanDto dto)
    {
        AuthInfo authInfo = SecurityUtils.getAuthInfo();
        CalendarPlan insert = new CalendarPlan();
        BeanUtils.copyProperties(dto, insert);
        insert.setDelStatus(BooleanEnum.TRUE.getCode());
        insert.setPlanType(2);
        insert.setCreateBy(authInfo.getPersonId());
        insert.setOrgCode(authInfo.getOrgCode());
        return toAjax(calendarPlanService.insertCalendarPlan(insert));
    }

    /**
     * 修改周行事历工作计划
     */
    @ApiOperation("修改工作计划")
    @PutMapping
    public AjaxResult edit(@RequestBody UpdateCalendarPlanDto dto)
    {
        CalendarPlan update = new CalendarPlan();
        update.setId(dto.getId());
        update.setName(dto.getName());
        update.setPlanIndex(dto.getPlanIndex());
        update.setPlanContent(dto.getPlanContent());
        return toAjax(calendarPlanService.updateCalendarPlan(update));
    }

    /**
     * 删除周行事历工作计划
     */
    @ApiOperation("删除工作计划")
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(calendarPlanService.deleteById(id));
    }
}
